﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entities.PBKT;

namespace WindowsForms.PBKT
{
	public partial class FormLichThiDau : Form
	{
		public  LichThiDau ltd;
		public static bool state = false;
		public FormLichThiDau()
		{
			InitializeComponent();
			dgvLTD.AutoGenerateColumns = false;

		}

		private void btnLoad_Click(object sender, EventArgs e)
		{
			LoadLichThiDau(LichThiDau.Objects.All().ToList());
		}

		private void LoadLichThiDau(List<LichThiDau> list)
		{
			dgvLTD.DataSource = list;
			// dgvLTD.DataSource = LichThiDau.Objects.Find(x => x.MaDoi1 == "CTK33").ToList();

		}

		private void dgvLTD_CellContentClick(object sender, DataGridViewCellEventArgs e)
		{

			ltd = LichThiDau.Objects.GetById(dgvLTD.Rows[e.RowIndex].Cells[0].Value.ToString());
			if (e.ColumnIndex == 7)
			{
				state = true;
				FormThemTTLichThiDau frm = new FormThemTTLichThiDau(ltd);

				frm.ShowDialog();

			}
			if (e.ColumnIndex == 6)
			{
				//ltd = LichThiDau.Objects.GetById(dgvLTD.Rows[e.RowIndex].Cells[0].Value.ToString());
				try
				{
					if (LichThiDau.Objects.Delete(ltd))
						MessageBox.Show("Xóa thành công");
				}

				catch (Exception)
				{

					throw;
				}
			}
		}

		private void btnAdd_Click(object sender, EventArgs e)
		{
			FormThemTTLichThiDau frm = new FormThemTTLichThiDau(ltd);
			frm.ShowDialog();
		}



	}
}
